<?php

//入库查询
class GetYundanApp extends MallbaseApp
{


    function index()
    {
        $data = array();
        $pageIndex = empty($_REQUEST['pageIndex']) ? 1 : trim($_REQUEST['pageIndex']);
        //$wxNum = empty($_REQUEST['wxNum']) ? '123' : trim($_REQUEST['wxNum']);
        $wxNum = isset($_COOKIE['wxid'])?$_COOKIE['wxid']:'';
        if(empty($wxNum)){
            echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
            echo "<script>alert('授权未成功');  window.location.href='http://dskc.csrsfwl.com/index.php?app=login'; </script>  ";//使用weixin.php的页面
        }
        if ($this->checkUrl(WEB_SERVICE2)) {
            $client = new soapclient(WEB_SERVICE2);
            $client->soap_defencoding = 'utf-8';
            $client->decode_utf8 = false;
            $client->xml_encoding = 'utf-8';
            $param = array(
                'pjson' => '{"pageIndex":"' . $pageIndex . '","wxNum": "' . $wxNum . '"}');

            $result = $client->__Call("GetYundan", array($param));

            if (is_soap_fault($result)) {
                trigger_error("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_USER_ERROR);
            } else {
                $result = json_decode(json_encode($result->GetYundanResult), TRUE);
                $result = json_decode($result, true);
                if ($result['status'] == 1) {
                    $data = $result['result'];
                    $dataCount = $result['dataCount'];
                } else {
                    if ($result['result'] == '该用户未登录') {
                        echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
                        echo "<script>alert('请先绑定微信'); window.location.href='index.php?app=login&hist=getyundan&wxNum=".$wxNum."'; </script>  ";
                        exit();
                    } elseif (strstr($result['result'], '该用户无权')) {
                        echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
                        echo "<script>alert('$result[result]'); window.location.href='index.php?app=menu'; </script>  ";
                        exit();
                    }
                }

            }
        }

        $this->import_resource(array('script' => 'jquery.ui/jquery.ui.js,jquery.ui/i18n/' . i18n_code() . '.js',
            'style' => 'jquery.ui/themes/ui-lightness/jquery.ui.css'));
        if ($data) {
            $this->assign('getyundans', $data);
            $page = $this->_get_page();
            $page['item_count'] = $dataCount;
            $this->_format_pageweb($page);
            $this->assign('page_info', $page);
        }
        $this->display('getyundan.index.html');
    }


    //列表更多
    function listmore()
    {
        $SLM_Tid = isset($_REQUEST['id']) ? trim($_REQUEST['id']) : '';
        $data = array();
        $pageIndex = empty($_REQUEST['pageIndex']) ? 1 : trim($_REQUEST['pageIndex']);
        $wxNum = empty($_REQUEST['wxNum']) ? '123' : trim($_REQUEST['wxNum']);
        /*$wxNum = isset($_COOKIE['wxid'])?$_COOKIE['wxid']:'';
        if(empty($wxNum)){
            echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
            echo "<script>alert('授权未成功');  window.location.href='index.php?app=login'; </script>  ";//使用weixin.php的页面
        }*/
        if ($this->checkUrl(WEB_SERVICE2)) {
            $client = new soapclient(WEB_SERVICE2);
            $client->soap_defencoding = 'utf-8';
            $client->decode_utf8 = false;
            $client->xml_encoding = 'utf-8';
            $param = array(
                'pjson' => '{"pageIndex":"' . $pageIndex . '","wxNum": "' . $wxNum . '"}');

            $result = $client->__Call("GetYundan", array($param));
            if (is_soap_fault($result)) {
                trigger_error("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_USER_ERROR);
            } else {
                $result = json_decode(json_encode($result->GetYundanResult), TRUE);
                $result = json_decode($result, true);

                if ($result['status'] == 1) {
                    foreach ($result['result'] as $key => $val) {
                        if ($val['SLM_Tid'] == $SLM_Tid) {
                            $data = $val;
                            break;
                        }
                    }
                }

            }
        }
        if ($data) {
            $this->assign('getyundan', $data);
        }
        $this->display('getyundan.listmore.html');
    }


}
